public class remove_nth_node_from_end_of_list {
    class Solution {
        public ListNode removeNthFromEnd(ListNode head, int n) {
            ListNode dummyHead= new ListNode(-1);
            dummyHead.next=head;
            ListNode slow = dummyHead;
            ListNode fast = dummyHead;
            while(n-->0){
                fast=fast.next;
            }
            ListNode prev=null;
            while(fast!=null){
                prev=slow;
                slow=slow.next;
                fast=fast.next;
            }
            prev.next=slow.next;
            slow.next=null;
            return  dummyHead.next;
        }
    }
}
